package com.ruoyi.central.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.cache.common.CacheConstants;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.service.CustomServiceImpl;
import com.ruoyi.central.mapper.TopCentralControllerOutTaskHistoryMapper;
import com.ruoyi.central.domain.TopCentralControllerOutTaskHistory;
import com.ruoyi.central.service.ITopCentralControllerOutTaskHistoryService;
import com.ruoyi.common.utils.StringUtils;

/**
 * 历史外部任务Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-25
 */
@Service
@Slf4j
@CacheConfig(cacheNames = CacheConstants.EhcacheName.CONTINUAL_CACHE_NAME)
public class TopCentralControllerOutTaskHistoryServiceImpl extends CustomServiceImpl<TopCentralControllerOutTaskHistoryMapper,TopCentralControllerOutTaskHistory> implements ITopCentralControllerOutTaskHistoryService
{
    /**
     * 查询历史外部任务
     * 注意：只操作未被标记为删除的数据！
     * @param id 历史外部任务主键
     * @param columns 查询指定的列
     * @return 历史外部任务
     */
    @Override
    public TopCentralControllerOutTaskHistory selectById(Integer id, SFunction<TopCentralControllerOutTaskHistory,?> ... columns){

        if(StringUtils.isNotEmpty(columns)){
            return selectOne(lambdaQuery().select(columns).eq(TopCentralControllerOutTaskHistory::getId,id));
        }
        return super.selectById(id);
    }

    /**
     * 查询历史外部任务列表
     *
     * @param topCentralControllerOutTaskHistory 历史外部任务
     * @return 历史外部任务
     */
    @Override
    public List<TopCentralControllerOutTaskHistory> selectList(TopCentralControllerOutTaskHistory topCentralControllerOutTaskHistory)
    {
        return getBaseMapper().selectTopCentralControllerOutTaskHistoryList(topCentralControllerOutTaskHistory);
    }

    /**
     * 获取所有的历史外部任务数据
     * 注意：只操作未被标记为删除的数据！
     * @return Map<Integer,TopCentralControllerOutTaskHistory> 集合
     */
    @Cacheable
    @Override
    public Map<Integer,TopCentralControllerOutTaskHistory> selectAllMap(){

        return getBaseMapper().selectList(customLambdaQuery().select(TopCentralControllerOutTaskHistory::getId))
                .stream().collect(Collectors.toMap(TopCentralControllerOutTaskHistory::getId,v->v));
    }

    /**
     * 新增历史外部任务
     *
     * @param topCentralControllerOutTaskHistory 历史外部任务
     * @return 结果
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean insert(TopCentralControllerOutTaskHistory topCentralControllerOutTaskHistory)
    {
        return super.insert(topCentralControllerOutTaskHistory);
    }

    /**
     * 新增（批量）历史外部任务
     *
     * @param topCentralControllerOutTaskHistoryList 实体对象集合
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean insertBatch(Collection<TopCentralControllerOutTaskHistory> topCentralControllerOutTaskHistoryList, int batchSize) {
        return super.insertBatch(topCentralControllerOutTaskHistoryList, batchSize);
    }

    /**
     * 删除 历史外部任务 根据编号
     * @param id
     * @return true 删除成功 false 删除失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean deleteById(Serializable id) {
        return super.deleteById(id);
    }

    /**
     * 批量删除 历史外部任务 根据 编号集合
     * @param ids
     * @return true 删除成功 false 删除失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean deleteByIds(Collection<? extends Serializable> ids) {
        return super.deleteByIds(ids);
    }

    /**
     * 批量修改 历史外部任务 根据唯一编号
     * @param topCentralControllerOutTaskHistoryList
     * @param batchSize  更新批次数量
     * @return true 修改成功 false 修改失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean updateBatchById(Collection<TopCentralControllerOutTaskHistory> topCentralControllerOutTaskHistoryList, int batchSize) {
        return super.updateBatchById(topCentralControllerOutTaskHistoryList, batchSize);
    }

    /**
     * 修改 历史外部任务
     * @param  topCentralControllerOutTaskHistory
     * @param updateWrapper
     * @return
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean update(TopCentralControllerOutTaskHistory topCentralControllerOutTaskHistory, LambdaUpdateWrapper<TopCentralControllerOutTaskHistory> updateWrapper) {
        return super.update(topCentralControllerOutTaskHistory,updateWrapper);
    }

    /**
     * 修改历史外部任务
     *注意：只操作未被标记为删除的数据！
     * @param topCentralControllerOutTaskHistory 历史外部任务
     * @return 结果
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean updateById(TopCentralControllerOutTaskHistory topCentralControllerOutTaskHistory)
    {
        return super.updateById(topCentralControllerOutTaskHistory);
    }


}
